// component/comment/comments.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    hasNextPage: Boolean,
    vlogComment: Object,
  },

  /**
   * 组件的初始数据
   */
  data: {
    isLike: false,
    imgUrl: getApp().globalData.uploadsUrl,
    sonIdx: 1
  },

  /**
   * 组件的方法列表
   */
  methods: {
    handleClickLike (e) {
      if (e.currentTarget.dataset.likeId) {
        let likeId = e.currentTarget.dataset.likeId
        let isLike = e.currentTarget.dataset.isLike
        console.log(likeId);
        this.triggerEvent('handleClickCommentLike', {
          likeId,
          isLike
        })
      }
      this.setData({
        isLike: e.currentTarget.dataset.isLike
      })
    },
    //按下事件开始
    mytouchstart: function (e) {
      let that = this;
      that.setData({
        touch_start: e.timeStamp
      })
    },
    //按下事件结束
    mytouchend: function (e) {
      let that = this;
      that.setData({
        touch_end: e.timeStamp
      })
    },
    handleOpenComment (e) {
      console.log('触摸他人评论',e)
      //触摸时间距离页面打开的毫秒数
      var touchTime = this.data.touch_end - this.data.touch_start;
      //如果按下时间大于350为长按
      if (touchTime < 350) {
        if (e.currentTarget.dataset.replyId) {
          let replyId = e.currentTarget.dataset.replyId
          let replyName = e.currentTarget.dataset.replyName
          let parentId = e.currentTarget.dataset.parentId
          let userId = e.currentTarget.dataset.userId
          this.triggerEvent('handleOpenComment', {
            isFocusInput: true,
            replyId,
            replyName,
            parentId,
            userId
          });
        } else {
          this.triggerEvent('handleOpenComment', {
            isFocusInput: true
          });
        } 
      } else {
        let replyId = e.currentTarget.dataset.replyId
        let userId = e.currentTarget.dataset.userId
        this.triggerEvent('handleToDeleteComment', {
          replyId,
          userId,
        });
      }
      
    },
    handleToShowMoreReply(e) {
      console.log(e.currentTarget.dataset.id);
      let id = e.currentTarget.dataset.id
      this.triggerEvent('handleToShowMoreReply', {
        pid: id
      });
    },
    handleToDeleteComment () {
      let id = e.currentTarget.dataset.id
      this.triggerEvent('handleToShowMoreReply', {
        pid: id
      });
    }

  }
})
